package cn.findviewbydream.evil.main.controller;

import cn.findviewbydream.evil.main.entity.BaseSeatEntity;
import cn.findviewbydream.evil.main.service.SettingBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.util.List;

/********************************************
 * 工程名：MealOrder
 * 包名：cn.findviewbydream.evil.main.controller
 * 时间：17-2-21
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：设置界面->饭店基础信息
 ********************************************/
@Controller
public class SettingBaseController
{
    private final SettingBaseService settingBaseService;

    @Autowired
    public SettingBaseController(SettingBaseService settingBaseService) {this.settingBaseService = settingBaseService;}

    @RequestMapping("/setting/base")
    public String index(Model model)
    {
        model.addAttribute("typeList", settingBaseService.getTypeList());
        model.addAttribute("essential", settingBaseService.getBaseEssentialInfo());
        return "setting/base";
    }

    @RequestMapping("/setting/get/list/seat")
    @ResponseBody
    public List<BaseSeatEntity> getBaseSeatList()
    {
        return settingBaseService.getBaseSeatList();
    }


    @RequestMapping("/setting/get/seat")
    @ResponseBody
    public BaseSeatEntity getBaseSeat(String id)
    {
        return settingBaseService.getBaseSeatById(id);
    }

    @RequestMapping("/setting/get/seat/last/id")
    @ResponseBody
    public int getBaseSeatLastId()
    {
        return settingBaseService.getBaseSeatLastId();
    }


    @RequestMapping(value = "/setting/post/seat", method = RequestMethod.POST)
    @ResponseBody
    public boolean postNewBaseSeat(int id, String seat, boolean state)
    {
        return settingBaseService.postBaseSeat(id, seat, state);
    }

    @RequestMapping(value = "/setting/post/seat/state", method = RequestMethod.POST)
    @ResponseBody
    public boolean postBaseSeatState(int id, boolean state)
    {
        return settingBaseService.postBaseSeatState(id, state);
    }

    /**
     * 有图片提交
     */
    @RequestMapping(value = "/setting/post/essential/submit_img", method = RequestMethod.POST)
    @ResponseBody
    public boolean postEssentialSubmit(String name, String address, String introduction,
                                       String type, @RequestParam(required = false) CommonsMultipartFile img)
    {
        return settingBaseService.postEssentialSubmit(name, address, introduction, type, img);
    }

    /**
     * 无图片提交
     */
    @RequestMapping(value = "/setting/post/essential/submit", method = RequestMethod.POST)
    @ResponseBody
    public boolean postEssentialSubmitWithoutImg(String name, String address, String introduction, String type)
    {
        return settingBaseService.postEssentialSubmit(name, address, introduction, type, null);
    }
}